package normalapi;

import java.math.BigInteger;
import java.util.Random;

public class BigIntegerDemo {
    public static void main(String[] args) {
        //获取随机大整数 表示 0-2的numBits 次方减1
        BigInteger num = new BigInteger(8,new Random());
        System.out.println(num);//0-2的八次方随机数

        //获取指定大整数
        BigInteger num2 = new BigInteger("999999999999999");
        System.out.println(num2);

        //获取指定进制的大整数
        BigInteger num3 = new BigInteger("10011",2);
        System.out.println(num3);

        //BigInteger 常用方法
        //add 加
        BigInteger num4 = num.add(num2);
        //subtract 减
        BigInteger num5 = num.subtract(num2);
        //multiply 乘
        BigInteger num6 = num.multiply(num2);
        //divide 除
        BigInteger num7 = num.divide(num2);
        //remainder 取余
        BigInteger num8 = num.remainder(num2);
        //除余
        BigInteger[] num81 = num.divideAndRemainder(num2);
        System.out.println("商："+num81[0]+" 余数："+num81[1]);
        //pow 幂
        BigInteger num9 = num.pow(2);
        //gcd 最大公约数
        BigInteger num10 = num.gcd(num2);
        //abs 绝对值
        BigInteger num11 = num.abs();
        //negate 相反数
        BigInteger num12 = num.negate();
        //min 最小值
        BigInteger num13 = num.min(num2);
        //max 最大值
        BigInteger num14 = num.max(num2);
        //equals 比较
        boolean num15 = num.equals(num2);
        //compareTo 比较
        int num16 = num.compareTo(num2);
        //转为 int类型
        int num17 = num.intValue();
        //转为 long类型
        long num18 = num.longValue();
        //转为 float类型
        float num19 = num.floatValue();
        //转为 double类型
        double num20 = num.doubleValue();
    };
}
